﻿<html>
<head>
<title>JavaScript冒泡排序</title>
</head>
<script>
	function bubbleSort(arr){    
		var i = arr.length -1;   
		while(i>0){    
			var position = 0; 
			for(var j = 0; j < i; j ++){    
				if(arr[j]>arr[j+1]){    
					position = j;    
					var temp = arr[j+1];    
					arr[j+1] = arr[j];    
					arr[j] = temp;    
				}    
			}    
			i = position;   
			console.log(arr.toString());			
		}    
		return arr;    
	}
	var array = [59,34,25,67,15,87,10,99,3,45]; 
	var res_arr = bubbleSort(array);
	console.log("最终排序结果为："+res_arr.toString());
</script>
</html>
